package com.wxb.pm.Exception;


import com.wxb.pm.common.BaseResponse;
import com.wxb.pm.common.ErrorCode;
import com.wxb.pm.common.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler
    public BaseResponse<?> businessExceptionHandler(BusinessException e){
        log.error("businessException" + e.getMessage(),e);
        return ResponseUtils.error(e.getCode(),e.getMessage(),e.getDescription());
    }

    public BaseResponse<?> runtimeExceptionHandler(RuntimeException e){
        log.error("runtimeException",e);
        return ResponseUtils.error(ErrorCode.SYSTEM_ERROR,e.getMessage(),"");
    }
}
